package com.bawei.router.interceptor

import android.content.Context
import com.alibaba.android.arouter.facade.Postcard
import com.alibaba.android.arouter.facade.annotation.Interceptor
import com.alibaba.android.arouter.facade.callback.InterceptorCallback
import com.alibaba.android.arouter.facade.template.IInterceptor

/**
 * Author: Jason Zhang
 * Date: 2024/12/14
 * Desc: 自定义路由拦截器
 */
@Interceptor(priority = 5, name = "路由参数拦截器")
class RouteParamsInterceptor: IInterceptor {

    private lateinit var mContext: Context

    //需要拦截Path路径
    private val needInterceptorPaths = arrayOf("")

    /**
     * 初始化方法，只会执行一次
     */
    override fun init(context: Context?) {
        if (context != null) {
            mContext = context
        }
    }

    /**
     * 拦截操作
     */
    override fun process(postcard: Postcard, callback: InterceptorCallback) {
        if (needInterceptorPaths.contains(postcard.path) && !postcard.extras.containsKey("traceId")){
            postcard.withString("traceId", "123")
        }
        //继续执行跳转逻辑
        callback.onContinue(postcard)
    }


}